<template>
	<view class="main">
		<view class="" style="background-color: #FFFFFF;margin: 10px;border-radius: 5px;">
			<view v-if="cartInfo&&cartInfo.length" style="padding-top: 2px;">
				<view class="" style="font-size: 18px;margin: 5px 12px;color: #000;font-weight: 700;">
				{{productInfo.store_name}}
				</view>
				<view class="" style="margin-left: 12px;">
					{{productInfo.attrInfo.suk}}
				</view>
			</view>
			<uni-view class="line" style="margin: 10px 12px;"></uni-view>
			<view style="margin: 5px 0 5px 12px;color: #000000;font-size: 18px;font-weight: 600;height: 30px;">选择日期</view>
			<view class="column" :style="isSelected?'background-color: rgb(244, 244, 244)':'background-color: rgb(255,243,245)'" style="padding:12px;;border-radius: 5px;margin: 0 12px 10px 12px;">
				<view class="row" style="">
					<view class="row" style="">
						<view  @click="selectDay(item)" :style="item.selected?'background:#007AFF;color:#fff !important':''" class="scroll-view-item_H columnn" v-for="(item,index) in twoSalesDate" v-if="twoSalesDate&&twoSalesDate.length" :key="index">
							<view> 
							<text :style="item.selected?'color: #fff;margin: 5px;font-size: 10px;':'color: #007AFF;margin: 5px;font-size: 10px;'">{{item.date_simple}}</text>
							<text :style="item.selected?'color: #fff;font-size: 10px;margin-right: 5px;':'color: #007AFF;font-size: 10px;margin-right: 5px;'">{{item.week}}</text>
							</view>
							<view>
								<text :style="item.selected?'color: #fff;font-size: 10px;':'color: #fd5f33;font-size: 10px;'">￥</text>
								<text :style="item.selected?'color: #fff;':'color: #fd5f33;'">{{item.price}}</text>
							</view>
						</view>
					</view>
					<view @click="calendarShow=true" v-if="salesDates&&salesDates.length>=3" class="row more_date" style="align-items: center;">
						<view class="columnn"  style="margin-left: 5px;">
							<view style="color: #000;font-size: 10px;">更多</view>
							<view style="color: #000;font-size: 10px;">日期</view>
						</view>
						 <text class="iconfont iconxiayiyeqianjinchakangengduo " style="color: #8a8a8a;margin-right: 5px;"></text>
						 
					</view>
				</view>
				<view v-if="!isSelected" class="row-center" style="">
					<icon type="info" size="15" color="#fc5145" style="margin-left: 15px;margin-right: 3px;"/>
					<text style="color: #fc5145;">请选择日期</text>
				</view>
			</view>
			<uni-view class="line" style="margin: 10px 12px;"></uni-view>
		    <view class="row" style="padding: 0 0 10px 12px;align-content: center;">
				<view class="column" @click="goNotice">
					<view style="color: #000000;font-size: 18px;font-weight: 600;">选择数量</view>
				</view>
				<view  class="column" style="margin-left: auto;margin-right: 12px;align-items: flex-end;">
					<u-number-box v-model="peopleNum"  :min="min" @minus="minus" @plus="plus" :disabled-input="true"></u-number-box>
				</view>
		   </view>
		</view>
		
		<view class="" style="background-color: #FFFFFF;margin: 10px;border-radius: 5px;">
			<view style="">
				
				
			</view>
		</view>
		
		
		<view class="" style="background-color: #FFFFFF;margin: 10px;border-radius: 5px;">
			<view style="padding-bottom: 5px;">
				<view class="row" style="align-items: center;background-color: #d9efff;border-top-left-radius: 5px;border-top-right-radius: 5px;">
					<view class="" style="font-size: 18px;margin: 5px 12px;color: #000;font-weight: 500;">
					游客信息
					</view>
					<view style="color: #a3a3a3;font-size: 12px;">需填写<text style="color: #cc1616;">{{peopleNum}}</text>位，用于入园身份验证</view>
					
				</view>
				<view @click="passengerShow=true" v-if="passengerList&&!passengerList.length" class="" style="border-radius: 5px;height: 35px;line-height: 35px;color: #FFFFFF;margin: 10px;background-color: #007AFF;text-align: center;">
					<view><text class="iconfont iconkuaidiyuan-xianxing"></text>添加乘客</view>
				</view>
				<view v-else  style="display: flex;flex-flow: wrap;margin: 10px 12px;">
					<view @click="selectPassenger(index)"  :class="item.check?'in-active':'no-active'" v-for="(item,index) in passengerList" :key="item.id" style="">
						<text>{{item.name}}</text>
						<view v-if="item.check" class="gou">
							<text class="iconfont iconzhengquewancheng" style="font-size: 10px;"></text>
						</view>
						<text style="display: none;">{{flag}}</text>
					</view>
					
					
					<view @click="passengerShow=true" class="no-active" style="">
						<text class="iconfont iconjia" style="font-size: 12px;"></text>更多
					</view>
				</view>
				<view class="">
					
					<view v-if="item.check" class="" v-for="(item, index) in passengerList" :key=index>
						<view class="row-center" style="margin: 5px 12px;">
							<text @click="delectPassenger(index)" class="iconfont iconshanchu4" style="color: #ff0004;margin: 0 10px 0 5px;"></text>
							<text style="font-size: 14px;color: #000000;font-weight: 600;width: 90px;">{{item.name}}</text>
							<text style="color: #909090;font-size: 12px;margin: 0 5px;margin-right: 32px;">{{item.id_card.substr(0,4) + "**********" + item.id_card.substr(14),}}</text>
							<view class="" style="width: 80px;height: 20px;line-height: 20px;font-size: 12px;background-color: #e4f4ff;color: #b5cdff;text-align: center;margin-right: 10px;">
								{{item.type==1?'成人票':'儿童票'}}
							</view>
							<text  @click="editPassenger(item)"  class="iconfont iconbianji2" style="margin-left: auto;font-size: 18px;color: #007AFF;"></text>
						
						</view>
						<view v-if="index!=(passengerList.length-1)" class="separation-line" style="margin: 12px;">
							
						</view>
					</view>
								
					
				</view>
				
			
			</view>
		</view>
	
		
		<view class='footer acea-row row-between-wrapper'>
			<view class="t-num" style="flex: 1;">总计
				<text style="color: #E56D00;">{{totalTicket}}</text>
				张票
				<text style="margin-right: 20upx;"></text>
				优惠
				<text style="color: #E56D00;">{{couponMoney}}</text>
				元
			</view>
			<view class="money">
				<view style="flex: auto;margin-right: 10px;">合计:
					<text class='font-color'>￥{{totalPrice}}</text>
				</view>
				<view @click="SubOrder">
					<button class='settlement' style='z-index:100'>立即支付</button>
				</view>

		
		
			</view>
		</view>
		
		
		<u-popup v-model="passengerShow" mode="bottom" border-radius="14" height="650" :closeable="true" z-index='10'>
			<view style="margin-top: 10px;margin-left: 10px;">
				<view class="" style="font-weight: 600;font-size: 18px;">
					选择乘客
				</view>
				<navigator url="/pages/add_passenger/index">
					<view class="" style="border-radius: 20px;height: 35px;line-height: 35px;width: 90%;color: #2979ff;margin: 15px;background-color: #e5f9ff;text-align: center;">
						<text class="iconfont iconjia" style="margin-right: 5px;"></text> 新增乘客
					</view>
				</navigator>
				
				<scroll-view class="" scroll-y="true" style="height: 400rpx;">
					
					<view  class="" v-for="(item, index) in passengerList">
						<view class="row-center" style="margin: 5px 12px;">
							<text @click="editPassenger(item)"  class="iconfont iconbianji2" style="font-size: 25px;color: #007AFF;margin-right: 15px;"></text>
							<text style="font-size: 14px;color: #000000;font-weight: 600;width: 70px;">{{item.name}}</text>
							<text style="color: #909090;font-size: 12px;margin: 0 5px;margin-right: 25px;">{{item.id_card.substr(0,4) + "**********" + item.id_card.substr(14),}}</text>
							<view class="" style="width: 40px;height: 20px;background-color: #e4f4ff;color: #b5cdff;text-align: center;margin-right: 10px;">
								{{item.type==1?'成人':'儿童'}}
							</view>
							<view @click="selectPassenger(index)"  v-if="item.check" class="iconfont iconzhengqueshixin" style="margin-left: 12px;font-size: 25px;color: #007AFF;">
								
							</view>
							<view @click="selectPassenger(index)"  v-else class="iconfont iconcheckboxweixuanzhongda" style="margin-left: 12px;font-size: 25px;color: #007AFF;">
								
							</view>
						
						</view>
						<view v-if="index!=(passengerList.length-1)" class="separation-line" style="margin: 12px;">
							
						</view>
					</view>
								
					
				</scroll-view>
				
			</view>
		</u-popup>
	
		<u-popup mode="bottom" v-model="calendarShow" :safe-area-inset-bottom="true"  border-radius="20">
			<uni-calendar :lunar="true" :insert="true" :date="selectDayBean" class="uni-calendar--hook" :selected="info.selected" :showMonth="false" @change="dateChange"  />
		</u-popup>
        <u-toast ref="uToast" />
	</view>
</template>
<script>
	import {
		openPaySubscribe
	} from '@/utils/SubscribeMessage.js';
	import {getPassengerList,getUserInfo} from '@/api/user'
	import {
		orderConfirm,
		getCouponsOrderPrice,
		orderCreate,
		postOrderComputed
	} from '@/api/order.js';
	var util = require('@/common/js/util.js');
	var add = util.add;
	var mul = util.mul;
	var validateIdCard = util.validateIdCard
	var _formatFloat = util.formatFloat;
	var _getAge = util.getAge
	import {
		mapGetters
	} from "vuex";
	export default{
		components: {
		},
		computed: mapGetters(['isLogin']),
		data() {
			return {
			    //支付方式
				cartArr: [{
						"name": "微信支付",
						"icon": "icon-weixin2",
						value: 'weixin',
						title: '使用微信快捷支付',
						payStatus: 1,
					},
					{
						"name": "支付宝支付",
						"icon": "icon-zhifubao",
						value: 'alipay',
						title: '使用线上支付宝支付',
						payStatus: 1,
					},
					{
						"name": "余额支付",
						"icon": "icon-yuezhifu",
						value: 'yue',
						title: '可用余额:',
						payStatus: 1,
					},
					{
						"name": "线下支付",
						"icon": "icon-yuezhifu1",
						value: 'offline',
						title: '选择线下付款方式',
						payStatus: 2,
					}
				],
				isRefresh:false,
				disableFlag:false,
				passengerShow: false,
				isSelected: false,
				cardKeyboardShow:false,
				phoneShow: false,
				twoSalesDate:[],
				selectDayBean:'',
				showCalendar: false,
				info: {
					lunar: true,
					range: true,
					insert: false,
					selected: []
				},
				calendarShow:false,
				itemId:'',
				itemInfo:'',
				passengerForm: {
					index:'',
					name: '',
					phone: '',
					idCard:''
				},
			    passengerPopup: false,
				min:1,
				peopleNum: 1,
				passengerList:[
				],
				coupon_id: '',
				coupon_title: '',
				integral: 0,
				currentCouponIndex: -1,
				couponList: [],
				couponMoney: 0.00,
				totalPrice: 0,
				totalTicket: 0, // 票的张数
				flag:0,
				cartId:'',
				news:1,
				userInfo:'',
				cartInfo: [],
				integralRatio: "0",
				offlinePostage: "",
				orderKey: "",
				priceGroup: {},
				ChangePrice: 0, //使用积分抵扣变动后的金额
				formContent: '',
				payType: 'yue', //支付方式
				// payType: 'weixin', //支付方式
				
				openType: 1, //优惠券打开方式 1=使用
				active: 0, //支付方式切换
				coupon: {
					coupon: false,
					list: [],
					statusTile: '立即使用'
				}, //优惠券组件
				address: {
					address: false
				}, //地址组件
				addressInfo: {}, //地址信息
				pinkId: 0, //拼团id
				addressId: 0, //地址id
				couponId: 0, //优惠券id
				cartId: '', //购物车id
				userInfo: {}, //用户信息
				mark: '', //备注信息
				couponTitle: '请选择', //优惠券
				coupon_price: 0, //优惠券抵扣金额
				useIntegral: false, //是否使用积分
				integral_price: 0, //积分抵扣金额
				productInfo:'',
				salesDates:[],
				BargainId:0,
				combinationId:0,
				pinkId:0,
				seckillId:0,
				mark:'',
				system_store:0,
				from: '',
				shippingType:0,
				invChecked: '',
			}
				
		},
	    onLoad(options){
			this.itemId = 76
			
			// #ifdef H5
			this.from = this.$wechat.isWeixin() ? 'weixin' : 'weixinh5'
			// #endif
			// #ifdef MP
			this.from = 'routine'
			// #endif
			if (!options.cartId) return this.$util.Tips({
				title: '请选择要购买的产品'
			}, {
				tab: 3,
				url: 1
			});
		
			this.cartId = options.cartId;
			this.news = !options.new || options.new === '0' ? 0 : 1;
			if(this.isLogin ){
				this.initPassengerList()
				this.getConfirm();
				
			}
	
		},
		onShow() {
			if(this.isLogin ){
				
				var that = this;
				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				
				
				// #ifdef MP
				let res = currPage.data.isRefresh;
				
				//#endif
				// #ifdef H5
				let res = currPage.isRefresh;
				
				//#endif
				
				if(res) {
					that.initPassengerList()
					that.isRefresh = false
				}
				
			}
		},
		onReady() {
			},
		methods:{

            SubOrder: function(e) {
			    if(this.disableFlag) return
		       	this.disableFlag = true
			
				let that = this,
					data = {};

				if (!that.payType) return that.$util.Tips({
					title: '请选择支付方式'
				});
				var selectDay= '',isPassengerAll=true,passNum=0;
				var passList = [];
				that.salesDates.forEach(function(item){
					if(item.selected){
						selectDay = item.date_str
					}
				})	
				this.passengerList.forEach(function(res){
					if(res.check==true){
						passNum++
						passList.push(res)
					}
				})
				var tips = "";
				if (selectDay=='') {
					tips = "请选择日期";
				} else if(passNum!=that.peopleNum){
					tips = "您还差"+(that.peopleNum - passNum)+'个游客未添加';
	            } else if(that.productInfo.attrInfo.stock<passNum){
					tips = "库存不足";
				}
				if (tips) {
					return this.$util.Tips({
						title: err
					}); 
					this.disableFlag = false
					return;
				} 			
				this.disableFlag = false
				data = {

					formId: '',
					couponId: that.couponId,
					payType: that.payType,
					useIntegral: that.useIntegral,
					bargainId: that.BargainId,
					combinationId: that.combinationId,
					pinkId: that.pinkId,
					seckill_id: that.seckillId,
					mark: that.mark,
					store_id: that.system_store ? that.system_store.id : 0,
					'from': that.from,
					shipping_type: 0,
					'new': that.news,
					'invoice_id': that.invChecked,
					passenger_num: that.peopleNum,
					select_day: selectDay,
					passenger_list: passList,
				};
				if (data.payType == 'yue' && parseFloat(that.userInfo.now_money) < parseFloat(that.totalPrice))
					return that.$util.Tips({
						title: '余额不足！'
					});
			
				// #ifdef MP
				openPaySubscribe().then(() => {
					that.payment(data);
				});
				// #endif
				// #ifndef MP
				that.payment(data);
				// #endif
			},
			/***提交订单***/
			SubOrder2:function() {
				if(this.disableFlag) return
				
				uni.showLoading({
				    title: '正在创建...'
				});
				this.disableFlag = true
			// 验证提交信息
				let that = this;
				var selectDay= '',isPassengerAll=true,passNum=0;
				var passList = [];
				
				that.itemInfo.sales_dates.forEach(function(item){
					if(item.selected){
						selectDay = item.date_str
					}
				})
				
				
				this.passengerList.forEach(function(res){
					if(res.check==true){
						passNum++
						passList.push(res)
					}
				})
				
			
				
				var tips = "";
				if (selectDay=='') {
					tips = "请选择日期";
				} else if(passNum!=that.peopleNum){
					tips = "您还差"+(that.peopleNum - passNum)+'个游客未添加';
				} else if(that.itemInfo.stock<passNum){
					tips = "库存不足";
				}
					
			
				if (tips) {
					that.$u.toast(tips)
					this.disableFlag = false
					return;
				} 
			
		         this.disableFlag = false
				var sb_data = {
					item_id: that.itemId,
					product_id: that.itemInfo.product_id,
					passenger_num: that.peopleNum,
					select_day: selectDay,
					passenger_list: passList,
					use_integral :that.use_integral,
					coupon_id :that.coupon_id,
					
				}
			
		
				this.$u.api.createOrderTicket(sb_data).then(res => {
					uni.hideLoading()
					if (res.code == 0) {
			
						/**在小程序环境直接支付**/
						// #ifdef MP
						
						uni.showLoading({
						    title: '支付中...'
						});
						that.$u.api.payOrder({
							order_id: res.data.order_id,
							pay_type: 1
						}).then(res1 => {
							uni.hideLoading()
							uni.requestPayment({
								provider: 'weixin',
								orderInfo: res1.data.order.order_name,
								timeStamp: res1.data.param.timeStamp.toString(),
								nonceStr: res1.data.param.nonceStr,
								package: res1.data.param.package,
								signType: res1.data.param.signType,
								paySign: res1.data.param.paySign,
								success(res) {
									uni.navigateTo({
										url: '/pages/pay_success/success_scenic_ticket'
									});
								},
								fail(res) {
									that.$refs.uToast.show({
										title: '支付失败',
										type: 'error',
									})
								},
								complete(res) {
									// that.$refs.uToast.show({
									// 	title: '支付失败',
									// 	type: 'error',
									// })
								}
							})
						})
						// #endif
	
					}
				})
			
			
			},
			payment: function(data) {
				let that = this;
				uni.showLoading({
					title: '订单支付中'
				});
				orderCreate(that.orderKey, data).then(res => {
										let status = res.data.status,
						orderId = res.data.result.orderId,
						jsConfig = res.data.result.jsConfig,
						goPages = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=' + res.msg +
						'&type=3' + '&totalPrice=' + this.totalPrice
					switch (status) {
						case 'ORDER_EXIST':
						case 'EXTEND_ORDER':
						case 'PAY_ERROR':
							uni.hideLoading();
							return that.$util.Tips({
								title: res.msg
							}, {
								tab: 5,
								url: goPages
							});
							break;
						case 'SUCCESS':
							uni.hideLoading();
							if (that.BargainId || that.combinationId || that.pinkId || that.seckillId)
								return that.$util.Tips({
									title: res.msg,
									icon: 'success'
								}, {
									tab: 4,
									url: goPages
								});
							return that.$util.Tips({
								title: res.msg,
								icon: 'success'
							}, {
								tab: 5,
								url: goPages
							});
							break;	
						case 'WECHAT_PAY':
							that.toPay = true;
							// #ifdef MP
							/* that.toPay = true; */
							uni.requestPayment({
								timeStamp: jsConfig.timestamp,
								nonceStr: jsConfig.nonceStr,
								package: jsConfig.package,
								signType: jsConfig.signType,
								paySign: jsConfig.paySign,
								success: function(res) {
									uni.hideLoading();
									if (that.BargainId || that.combinationId || that.pinkId || that
										.seckillId)
										return that.$util.Tips({
											title: '支付成功',
											icon: 'success'
										}, {
											tab: 4,
											url: goPages
										});
									return that.$util.Tips({
										title: '支付成功',
										icon: 'success'
									}, {
										tab: 5,
										url: goPages
									});
								},
								fail: function(e) {
									uni.hideLoading();
									return that.$util.Tips({
										title: '取消支付'
									}, {
										tab: 5,
										url: goPages + '&status=2'
									});
								},
								complete: function(e) {
									uni.hideLoading();
									//关闭当前页面跳转至订单状态
									if (res.errMsg == 'requestPayment:cancel') return that.$util
										.Tips({
											title: '取消支付'
										}, {
											tab: 5,
											url: goPages + '&status=2'
										});
								},
							})
							// #endif
							// #ifdef H5
							this.$wechat.pay(res.data.result.jsConfig).then(res => {
								return that.$util.Tips({
									title: '支付成功',
									icon: 'success'
								}, {
									tab: 5,
									url: goPages
								});
							}).catch(res => {
								if (!this.$wechat.isWeixin()) {
									uni.redirectTo({
										url: goPages +
											'&msg=支付失败&status=2'
									})
								}
								if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
									title: '取消支付'
								}, {
									tab: 5,
									url: goPages + '&status=2'
								});
							})
							// #endif
					
							break;

					}
				}).catch(err => {
					uni.hideLoading();
					return that.$util.Tips({
						title: err
					});
				});
			},
			
			/**
			 * 获取当前订单详细信息
			 * 
			 */
			getConfirm: function() {
				let that = this;
				// return;
				orderConfirm(that.cartId, that.news).then(res => {
					that.$set(that, 'userInfo', res.data.userInfo);
					that.$set(that, 'integral', res.data.userInfo.integral);
					that.$set(that, 'cartInfo', res.data.cartInfo);
					that.$set(that, 'integralRatio', res.data.integralRatio);
					that.$set(that, 'offlinePostage', res.data.offlinePostage);
					that.$set(that, 'orderKey', res.data.orderKey);
		
					that.$set(that, 'priceGroup', res.data.priceGroup);
					// that.$set(that, 'totalPrice', that.$util.$h.Add(parseFloat(res.data.priceGroup.totalPrice),
					// 	parseFloat(res.data
					// 		.priceGroup.storePostage)));
	                that.$set(that, 'salesDates', res.data.cartInfo[0].productInfo['sales_dates']);
	                that.$set(that, 'productInfo', res.data.cartInfo[0].productInfo);
	
				    that.initDate(res.data.cartInfo[0].productInfo['sales_dates'])
			
					
					//微信支付是否开启
					that.cartArr[0].payStatus = res.data.pay_weixin_open || 0
					//支付宝是否开启
					that.cartArr[1].payStatus = res.data.ali_pay_status || 0;
					//#ifdef MP
					that.cartArr[1].payStatus = 0;
					//#endif
					//余额支付是否开启
					// that.cartArr[2].title = '可用余额:' + res.data.userInfo.now_money;
					that.cartArr[2].number = res.data.userInfo.now_money;
					that.cartArr[2].payStatus = res.data.yue_pay_status == 1 ? res.data.yue_pay_status : 0
					if (res.data.offline_pay_status == 2) {
						that.cartArr[3].payStatus = 0
					} else {
						that.cartArr[3].payStatus = 1
					}
		
					// that.$set(that, 'cartArr', that.cartArr);
					that.$set(that, 'ChangePrice', that.totalPrice);
					that.getCouponList();
					this.computedPrice();
				}).catch(err => {
					return this.$util.Tips({
						title: err
					});
				});
			},
			// 设置日期与价格
			initDate(sales_dates){
				let that = this
				that.twoSalesDate =  sales_dates.slice(0,2)
				console.log(5555,that.twoSalesDate)	
				this.$nextTick(() => {
							this.showCalendar = true
						})
			   // TODO 模拟请求异步同步数据
			
				this.info.selected = [];
				
				// 设置日期与价格
				for (var i = 0; i < sales_dates.length; i++) {
					this.info.selected.push({
						date: sales_dates[i].date_str,
						info: '￥' + parseFloat(sales_dates[i].price),
						surplus: 0
					})
				}
			},
			/**
			 * 获取当前金额可用优惠券
			 * 
			 */
			getCouponList: function() {
				let that = this;
				let data = {
					cartId: this.cartId,
					'new': this.news
				}
				getCouponsOrderPrice(this.totalPrice, data).then(res => {
					that.$set(that.coupon, 'list', res.data);
					that.openType = 1;
				});
			},
			
			computedPrice: function() {
				let shippingType = this.shippingType;
				postOrderComputed(this.orderKey, {
					addressId: this.addressId,
					useIntegral: this.useIntegral ? 1 : 0,
					couponId: this.couponId,
					shipping_type: 0,
					payType: this.payType
				}).then(res => {
					let result = res.data.result;
					if (result) {
						this.totalPrice = result.pay_price;
						this.integral_price = result.deduction_price;
						this.coupon_price = result.coupon_price;
						this.integral = this.useIntegral ? result.SurplusIntegral : this.userInfo.integral;
						this.$set(this.priceGroup, 'storePostage', shippingType == 1 ? 0 : result.pay_postage);
						this.$set(this.priceGroup, 'storePostageDiscount', result.storePostageDiscount);
					}
				})
			},
			/**选择乘客*/
			selectPassenger:function(index){
				let that = this
				if(!this.productInfo) return;
				var passenger = this.passengerList[index]
				var ageLimit = this.productInfo.attrInfo.age_limit
				
				// 儿童票
				if(ageLimit&&ageLimit<14&&_getAge(passenger.id_card)>ageLimit){
					return that.$util.Tips({title: '游客身份信息不满足年龄限制'})
				} else if(ageLimit&&ageLimit<=60&&_getAge(passenger.id_card)<ageLimit){
					return that.$util.Tips({title: '游客身份信息不满足年龄限制'})
				}
				
				passenger.check = !passenger.check
				
				
				var passNum = 0;
				this.passengerList.forEach(function(res){
					if(res.check==true){
						passNum++
					}
				})			
				if(passNum > this.peopleNum){
					this.passengerList[index].check = false
					uni.showModal({
					    title: '温馨提示',
					    content: '最多添加'+this.peopleNum+'个游客，请增加您的购票张数',
						showCancel: false,
						confirmText: '我已知晓',
					    success: function (res) {
					        if (res.confirm) {
					            console.log('用户点击确定');
					        } else if (res.cancel) {
					            console.log('用户点击取消');
					        }
					    }
					});
					
					return
				}  else{
					this.flag++
				}
				
				this.computePrice()
				
				
			},
			
			delectPassenger:function(index){
				this.passengerList[index].check = false
				this.flag++
			},
			
			editPassenger:function(item){
				uni.navigateTo({
					url:'/pages/add_passenger/index?id='+item.id+'&id_card='+item.id_card+'&name='+item.name+'&phone='+item.phone+'&type='+item.type
				})
			},
			
			initPassengerList:function(){
				let that = this
				getPassengerList().then(res => {
					
					that.passengerList = res.data
					
					that.passengerList.forEach(function(res,index) {
						// if(index==0){
						// 	that.passengerList[index].check = true
						// } else {
						// 	that.passengerList[index].check = false
						// }
						that.passengerList[index].check = false
						
					})
										
					// setTimeout(function(){
					// 	that.computePrice()
					// },100)
				})
			},
			goNotice:function(){
				uni.navigateTo({
					url: '/pages/web/web?url='+this.itemInfo.buy_notice
				})
			},
			

			
			/***选择日期**/
			selectDay:function(item){
				let that = this
				that.twoSalesDate = []
				that.salesDates.forEach(function(res,index){
					res.selected = false
					if(res.date == item.date){
						res.selected = true
						that.isSelected = true
						that.selectDayBean = res.date_str
						if(index==0){
							that.twoSalesDate = [
								res,that.salesDates[index+1]
							]
						}else{
							that.twoSalesDate = [
								that.salesDates[0],res
							]
						}
						
						
					}
				})
			     this.computePrice()
			},
			selectDayCalendar:function(item){
				let that = this
				that.salesDates.forEach(function(res,index){
					res.selected = false
					if(res.date_str == item.fulldate){
						res.selected = true
						that.isSelected = true
						that.selectDayBean = res.date_str
						if(index==0){
							that.twoSalesDate = [
								res,that.salesDates[index+1]
							]
						}else{
							that.twoSalesDate = [
								that.salesDates[0],res
							]
						}
					}
				})
				
				this.computePrice()
			},
			
			dateChange:function(date){
				this.selectDayCalendar(date)
				this.calendarShow =false
				
			},
			colsePassengerPopup:function(){
				this.passengerPopup = false
			},
			passengerPopupShow:function(passenger,index){
				this.passengerPopup = true
				this.passengerForm = {
					index:index,
					name: passenger.name,
					phone: passenger.phone,
					idCard:passenger.idCard
				}
				
			},
			minus:function(e){
				for(var i =0; i<this.passengerList.length;i++){
					if(this.passengerList[this.passengerList.length-i-1].check){
						this.passengerList[this.passengerList.length-i-1].check = false
						return
					}
				}
				this.computePrice()	
			},
			plus:function(){
				// this.passengerList.push(
				// {
				// 	phone:'',
				// 	name:'',
				// 	idCard:'',
				// })	
				this.computePrice()
			},
			
			computePrice() {
				var that = this;
				var itemInfo = that.productInfo.attrInfo,
					peopleNum = that.peopleNum,
					currentCouponIndex = that.currentCouponIndex;
				var totalPrice = 0;
				var selectDay= '';
						
				this.salesDates.forEach(function(item){
					if(item.selected){
						selectDay = item.date_str
					}
				})
					var price = selectDay==''?0:itemInfo.price
					totalPrice = _formatFloat(peopleNum* price, 2);
		
				
		
				var originTotalPrice = totalPrice
		
				//重新计算
				totalPrice = that.computeWithCouponPrice(that, totalPrice) ;
				totalPrice = that.computeWithIntegralPrice(that, totalPrice);
				totalPrice = that.computeWithFullReduction(that, totalPrice);
			         
			
				that.totalPrice = totalPrice
				
				that.totalTicket = peopleNum
				
				
				that.couponMoney = originTotalPrice - totalPrice;
			},
			//重新计算 优惠券 积分等等
			computeWithFullReduction(that, totalPrice) {
		
				if (!that.itemInfo.is_full_reduction) {
					return totalPrice;
				}
				var newPrice = totalPrice;
				
				if (totalPrice >= that.itemInfo.full_refuction_price) {
					newPrice = _formatFloat(totalPrice - that.itemInfo.sub_price, 2);
				}
				return Number(newPrice) > 0 ? Number(newPrice) : _formatFloat(0, 2);
			},
			
			//重新计算 优惠券 积分等等
			computeWithCouponPrice(that, totalPrice) {
				var currentCoupon = that.couponList.find((element) => (element.is_use == 1));
				that.coupon_id = currentCoupon ? currentCoupon.id : ''
				that.coupon_title = currentCoupon ? currentCoupon.coupon_title : ''
				if (!currentCoupon) {
					return totalPrice;
				}
				var newPrice = totalPrice;
				if (currentCoupon.coupon_type === 1) {
					newPrice = _formatFloat(totalPrice - currentCoupon.discount_price, 2);
				} else if (currentCoupon.coupon_type === 2) {
					newPrice = _formatFloat(totalPrice * currentCoupon.discount_price, 2);
				}
				return Number(newPrice) > 0 ? Number(newPrice) : _formatFloat(0, 2);
			},
			//重新计算 优惠券 积分等等
			computeWithIntegralPrice(that, totalPrice) {
				if (!that.useIntegral) {
					return totalPrice;
				}
				var newPrice = totalPrice;
				if (newPrice >= that.integral / 100) {
					newPrice = _formatFloat(newPrice - that.integral / 100, 2)
					that.integral = 0
				} else {
					newPrice = 0.01
					that.integral = (that.integral - newPrice * 100)
				}
			
			
				return Number(newPrice) > 0 ? Number(newPrice) : _formatFloat(0, 2);
			},
			blur:function(){
				uni.hideKeyboard()
			}
		},
	}
</script>

<style>
	.main {
	    background: linear-gradient(to bottom,#007AFF,#007AFF,#efeff4,#efeff4,#efeff4,#efeff4);
		height: 100%;
		padding-bottom: 80px;
		padding-top: 10px;
	}
		.scroll-view_H {
			white-space: nowrap;
			width: 100%;
		}
	.scroll-view-item_H {
		display: inline-block;
		/* width: 115rpx; */
		height: 90rpx;
		text-align: center;
		background-color: #FFFFFF;
		margin: 0 0 10px 10px;
		border-radius: 5px;
		border: 2px solid #dcdcdc;
	}
	.more_date{
		height: 90rpx;
		text-align: center;
		background-color: #FFFFFF;
		margin: 0 0 10px 10px;
		border-radius: 5px;
		border: 2px solid #dcdcdc;
	}
	
	.footer {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		height: 120upx;
		background-color: #fff;
		padding: 0 10px 0 10px;
		font-size: 32upx;
		color: #333;
		box-sizing: border-box;
		position: fixed;
		bottom: 0;
		left: 0;
		align-items: center;
		justify-content: space-between;
		z-index: 999;
	}
	
	.footer .font-color {
		color: #0c79ff !important;
	}
	
	.settlement {
		font-size: 30upx;
		color: #fff;
		width: 240upx;
		height: 70upx;
		background-color: #0c79ff;
		border-radius: 50upx;
		text-align: center;
		line-height: 70upx;
		margin-top: 4px;
	}
	
	.footer .t-num {
		font-size: 26upx;
		margin-top: 10upx;
	}
	
	.footer .money {
		display: flex;
		flex-wrap: wrap;
		height: 80upx;
		line-height: 80upx;
	}
	
	.no-active{
		width: 27%;
		height: 35px;
		border-radius: 5px;
		border: 1px solid #e5e5e5;
		margin: 0 15px 10px 0;
		text-align: center;
		line-height: 35px;
		position: relative;
	}
	.in-active{
		width: 27%;
		height: 35px;
		border-radius: 5px;
		border: 1px solid #0c79ff;
		margin: 0 15px 10px 0;
		text-align: center;
		line-height: 35px;
		position: relative;
	}
	.gou {
		position: absolute;
		float: right;
		right: 0;
		background-color: #0c79ff;
		width: 15px;
		height: 10px;
		line-height: 10px;
		bottom: 0;
		border-bottom-right-radius: 3px;
		border-top-left-radius: 5px;
	}
	.content {
		padding: 24rpx;
		text-align: center;
	}
</style>
